package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {
    @Autowired
    private ApArticleService apArticleService;

    /**
     * TODO
     *      - 加载首页
     *      - uri: /api/v1/article/load
     *      - method: post
     * @param articleHomeDto    请求体参数
     * @return                  ResponseResult
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.loadArticle(articleHomeDto);
    }

    /**
     * TODO
     *      - 加载更多
     *      - uri: /api/v1/article/loadmore
     *      - method: post
     * @param articleHomeDto    请求体参数
     * @return                  ResponseResult
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, 1);
    }

    /**
     * TODO
     *      - 加载最新
     *      - uri: /api/v1/article/loadnew
     *      - method: post
     * @param articleHomeDto    请求体参数
     * @return                  ResponseResult
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, 2);
    }
}
